home *** CD-ROM | disk | FTP | other *** search
- Path: news.mira.net.au!news
- From: davidw@werple.net.au (David White)
- Newsgroups: comp.lang.c++
- Subject: Re: Is this a memory leak?
- Date: 4 Apr 1996 21:33:38 +1000
- Organization: Werple Internet, Melbourne
- Message-ID: <4k0c2i$h6e@werple.net.au>
- References: <4jv214$gv7@insosf1.netins.net>
- NNTP-Posting-Host: werplez.mira.net.au
-
- hhowe@trgnet.com (Harold Howe) writes:
-
- >Could someone please tell me if this code leaks memory
-
- >class BuriedClass
- > {
- > ...
- > }
-
- >class TopClass
- > {
- > private
- > BuriedClass *bury;
- > public:
- > TopClass::TopClass() { bury = new BuriedClass();}
- > shutDown { bury = 0;}
- > ~TopClass { delete bury}
- > }
-
- >int main(void)
- > {
- > TopClass *top = new TopClass();
- > top->shutDown();
- > delete top;
- > return 0;
- > }
-
- >Is the memory that was alloced for the buried class lost? If not please
- >describe how it was freed. Does zeroing the pointer free the memory? The
- >delete is a waste of time on a zeroed pointer, isn't it.
-
- The BuriedClass object is not deleted. Zeroing the pointer does nothing
- but zero the pointer, which prevents the BuriedClass object from being
- deleted. Maybe 'shutDown' is intended to be called if responsibility for
- the BuriedClass object is moved to something else, which will delete it,
- or maybe it's a safety measure, to be used if some sort of free store
- corruption is detected.
-
- David White
- davidw@werple.mira.net.au
-